﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace OpenNETCF.Bookshare.Services
{
    internal class LibraryService : ILibraryService
    {
        private List<IBookInfoService> InfoServices { get; set; }

        public LibraryService()
        {
            InfoServices = new List<IBookInfoService>();

            InfoServices.Add(new IsbnDbService());
        }

        public string LookupByISBN(string ISBN)
        {
            foreach (var svc in InfoServices.OrderByDescending(s => s.Priority))
            {
                var result = svc.LookupByISBN(ISBN);

                if (result != null)
                {
                    return result;
                }
            }

            return null;
        }

        public string LookupByAuthor(string name)
        {
            foreach (var svc in InfoServices.OrderByDescending(s => s.Priority))
            {
                var result = svc.LookupByAuthor(name);

                if (result != null)
                {
                    return result;
                }
            }

            return null;
        }

    }
}
